package com.tiandawu.injectframwork.proxy;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * Created by tiandawu on 2017/3/27.
 */

public class ListenerInvocationHandler implements InvocationHandler {

    private Context mContext;
    private Map<String, Method> mMethodMap;

    public ListenerInvocationHandler(Context context, Map<String, Method> methodMap) {
        this.mContext = context;
        this.mMethodMap = methodMap;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String name = method.getName();
        Method mMethod = mMethodMap.get(name);
        Log.e("tt", "method = " + mMethod.getName());
        if (mMethod != null) {
            return mMethod.invoke(mContext, args);
        } else {
            return method.invoke(proxy, args);
        }
    }
}
